//
//  ByViewMineUpdateAuthImage.m
//  mijifen_ios
//
//  Created by 朱凯 on 2017/10/23.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByViewMineUpdateAuthImage.h"

@implementation ByViewMineUpdateAuthImage
{
    ByIconChooseDataSource *_source;
    
    UIImageView *_contentView;
    
    UIImageView *_addImageView;
    UILabel     *_noteLabel;
}
- (instancetype)init {
    
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}
- (void)setupUI {
    
    self.backgroundColor = [UIColor whiteColor];
    self.layer.masksToBounds = true;
    self.layer.cornerRadius = 4;
    
    // 内容
    _contentView = [UIImageView new];
    [self addSubview:_contentView];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    
    // +号
    _addImageView = [UIImageView new];
    _addImageView.image = [UIImage imageNamed:@"加"];
    [self addSubview:_addImageView];
    [_addImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(self).multipliedBy(0.4);
        make.width.equalTo(_addImageView.mas_height);
        make.centerX.equalTo(self);
    }];
    
    // note
    _noteLabel = [[UILabel alloc] init];
    _noteLabel.adjustsFontSizeToFitWidth = true;
    _noteLabel.numberOfLines = 1;
    _noteLabel.text = @"";
    _noteLabel.font = FONT(16);
    _noteLabel.textAlignment = NSTextAlignmentCenter;
    _noteLabel.textColor = [UIColor lightGrayColor];
    [self addSubview:_noteLabel];
    [_noteLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.height.equalTo(self).multipliedBy(0.4);
        make.bottom.equalTo(self);
        make.top.equalTo(_addImageView.mas_bottom);
    }];
}

- (void)setNote:(NSString *)note {
    
    _note = note;
    _noteLabel.text = note;
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    _source = [[ByIconChooseDataSource alloc] init];
    [_source fireWithViewController:self.viewController];
    [_source makeConfigToSelectIcon];
    __weak typeof(self) wself = self;
    [_source setCompleteBlock:^(UIImage *image) {
        typeof(self) ssefl = wself;
        ssefl.image = image;
        image = [image getCenterRatilImageWithRatio:self.width / self.height];
        ssefl->_contentView.image = image;
        [ssefl bringSubviewToFront:ssefl->_contentView];
    }];
}
@end
